package com.example.myapplication.a_utils;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class MyRetrofit {
    private MyRetrofit() {
    }
    private static MyRetrofit myRetrofit;
    public static MyRetrofit getInstance(){
        if (myRetrofit == null){
            synchronized (MyRetrofit.class){
                if (myRetrofit == null){
                    myRetrofit = new MyRetrofit();
                }
            }
        }
        return myRetrofit;
    }

    private Retrofit retrofit;
    public Retrofit getRetrofit(String path){
        if (retrofit == null){
            retrofit = new Retrofit.Builder()
                    .baseUrl(path)
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .client(new OkHttpClient.Builder().addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).build())
                    .build();
        }
        return retrofit;
    }

}
